export default function formatMessageTime(timestamp) {
	if(!timestamp||0) return false
    const now = new Date();
    const messageDate = new Date(timestamp);

    // 计算时间差（以毫秒为单位）
    const diff = now - messageDate;
    const diffInMinutes = Math.floor(diff / (1000 * 60));
    const diffInHours = Math.floor(diff / (1000 * 60 * 60));
    const diffInDays = Math.floor(diff / (1000 * 60 * 60 * 24));
    const diffInMonths = now.getMonth() - messageDate.getMonth() + (now.getFullYear() - messageDate.getFullYear()) * 12;
    const diffInYears = now.getFullYear() - messageDate.getFullYear();

    if (diffInMinutes < 1) {
        return "刚刚";
    } else if (diffInHours < 1) {
        return `${diffInMinutes}分钟前`;
    } else if (diffInHours < 12) {
        return `${messageDate.getHours().toString().padStart(2, '0')}:${messageDate.getMinutes().toString().padStart(2, '0')}`;
    } else if (diffInMonths < 1) {
        return `${messageDate.getMonth() + 1}月${messageDate.getDate()}号${messageDate.getHours().toString().padStart(2, '0')}:${messageDate.getMinutes().toString().padStart(2, '0')}   `;
    } else if (diffInYears < 1) {
        return `${messageDate.getMonth() + 1}月${messageDate.getDate()} 号`;
    } else {
        return `${messageDate.getFullYear()}年${messageDate.getMonth() + 1}月${messageDate.getDate()}号${messageDate.getHours().toString().padStart(2, '0')}:${messageDate.getMinutes().toString().padStart(2, '0')}`;
    }
}